package com.mhwx.mhlive.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.mhwx.mhlive.R;
import com.mhwx.mhlive.ui.activity.MediaclDatails;
import com.mhwx.mhlive.ui.adapter.MedicalAdapter;
import com.mhwx.mhlive.ui.base.BaseFragment;
import com.mhwx.mhlive.util.IntoActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrHandler;

/**
 * 类功能描述
 *医疗类
 * @author Guol
 * @version 1.0
 * @copyright 北京明华维新信息技术有限公司
 * @time 2017/5/2
 */
public class MedicalFragemnt extends BaseFragment {

    public static String TABLAYOUT_FRAGMENT = "tab_fragment";
    private int type;

    @BindView(R.id.recycler)
    RecyclerView recycler;

    @BindView(R.id.rotate_header_grid_view_frame)
    PtrClassicFrameLayout mPtrFrame;

    private List<String> mDatas;

    private MedicalAdapter mAdapter;
    @Override
    protected int getLayoutRes() {
        return R.layout.frg_medical;
    }

   public static MedicalFragemnt newInstance(int type ){
       MedicalFragemnt fragment = new MedicalFragemnt();
       Bundle bundle = new Bundle();
       bundle.putSerializable(TABLAYOUT_FRAGMENT, type);
       fragment.setArguments(bundle);
       return fragment;

   }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        init();
    }

    private void init(){
        mDatas = new ArrayList<String>();

        recycler.setLayoutManager(new LinearLayoutManager(getContext()));
        mPtrFrame.setLastUpdateTimeRelateObject(this);
        mPtrFrame.setPtrHandler(new PtrHandler() {
            @Override
            public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
                return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);
            }

            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
                mPtrFrame.refreshComplete();
                initData();
            }

        });
    }

    private void initData(){
        for (int i = 'A'; i < 'z'; i++)
        {
            mDatas.add("" + (char) i);
        }
        if (mAdapter==null) mAdapter=new MedicalAdapter(getContext(),mDatas);
        recycler.setAdapter(mAdapter);
        mAdapter.setOnRecyclerViewItemClickListener(new BaseQuickAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int i) {
                IntoActivity.toNextActivity(getContext(), MediaclDatails.class);

            }
        });
    }
}
